<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>系统菜单</title>
<%@ include file="../../header_inc.jsp"%>
<style type="text/css" media="screen">
.btn{
   	border-right: #63B8FF 1px solid;
  	padding-right: 2px;
   	border-top: #63B8FF 1px solid;
   	padding-left: 2px;
   	font-size: 12px;
   	FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,  StartColorStr=#ffffff,  EndColorStr=#C3DAF5);
   	border-left: #63B8FF 1px solid;
   	cursor: hand;
   	color: black;
   	padding-top: 2px;
   	border-bottom: #63B8FF 1px solid;
}
</style>
<script type="text/javascript">
  //状态格式化
    function showOpt(value,rec,index)
    {
    	if(value == 9)
    	{
    		return '<a href="#" onclick="cancel_fun();"><input class="btn"  type="button" value="启用" ></a>';
    	}
    	else if(value == 1)
    	{
    		return '<a href="#" onclick="normal_fun();"><input class="btn" type="button" value="禁用" ></a>';
    	}
    }
  //一键启用
    function normal_fun()
    {
    	var id;
    	var row = $('#dg').datagrid('getSelected');
    	id=row.id;
        if(!row)
        {
            $.messager.alert("系统提示","请选择要启用的菜单！");
        }
        else
        {
            $.messager.confirm("确认","是否要启用这个菜单？",function(conf){
                if(conf)
                {
                    var url = "${ctx}/manage/sysMenus/openMenu?id="+id;
                    $.getJSON(url, function(json){
                        if(json.success==0)
                        {
                        	
                        	$('#dg').treegrid('uncheckAll');
                        	$('#dg').treegrid('reload');
                        }
                        else
                        {
                        	$.messager.alert("系统提示",json.msg);
                        }
                    });
                }                                       
            });
        }
    }
  //一键禁用
    function cancel_fun()
    {
    	var id;
    	var row = $('#dg').datagrid('getSelected');
    	id=row.id;
        if(!row)
        {
            $.messager.alert("系统提示","请选择要禁用的菜单！");
        }
        else
        {
            $.messager.confirm("确认","是否要禁用这个菜单？",function(conf){
                if(conf)
                {
                	var url = "${ctx}/manage/sysMenus/closeMenu?id="+id;
                    $.getJSON(url, function(json){
                        if(json.success==0)
                        {
                        	
                        	$('#dg').treegrid('uncheckAll');
                        	$('#dg').treegrid('reload');
                        }
                        else
                        {
                        	$.messager.alert("系统提示",json.msg);
                        }
                    });
                }                                       
            });
        }
    }
    </script>
  </head>
  <body class="easyui-layout">
    <div data-options="region:'center',border:false"
            style="overflow: hidden;padding:0px" fit="true">
	    <table id="dg" title="功能管理列表" fit="true"  
	        url="${ctx }/manage/sysMenus/dataGrid" method="get" data-options="toolbar:'#toolbar'" pagination="false" singleSelect="false" rownumbers="true" idField="id" treeField="name">    
		    <thead>    
		        <tr>
		        	<th data-options="field:'ck',checkbox:true">全选</th>    
		            <th field="name" width="160" align="left">菜单名</th>    
                    <th field="type" width="80" align="center" formatter="showType">类型</th>    
		            <th field="url" width="200" align="left">URL地址</th>    
		            <th field="showOrder" width="80" align="center">显示顺序</th>    
		            <th field="img" width="100" align="center">显示图标</th>  
		            <!--  <th field="status" width="80" align="center" formatter="showStatus">当前状态</th>-->  
		            <th field="status" width="80" align="center" formatter="showOpt">状态</th>
		            <!--<th data-options="field:'_operate1',width:90,align:'center',formatter:formatper">操作</th>  -->		           
		        </tr>    
		    </thead>    
		</table>
	</div> 
	<!-- 功能菜单 -->
		<div id="toolbar" style="display: none; background: #F0FFF0" align="left">
		${buttons }
            <script type="text/javascript">
            function append()
            {
                var params = {
                        winId:'win_add_modules',
                        title:'添加功能菜单',
                        width:400,
                        height:330,
                        showUrl:'${baseUrl}/manage/sysMenus/add',
                        refresh_fun:function(){
                            $('#dg').treegrid('reload');
                        }
                        
                };
            	open_fun(params);
            }
            function edit()
            {
                var id=0;
                var row = $('#dg').datagrid('getSelected');
                if(row)
                {
                    id = row.id;
                }
                if(id>0)
                {
                    var params = {
                            winId:'win_edit_modules',
                            title:'修改功能菜单',
                            width:400,
                            height:330,
                            showUrl:'${baseUrl}/manage/sysMenus/edit?id='+id,
                            refresh_fun:function(){
                                $('#dg').treegrid('reload');
                            }
                            
                    };
                	open_fun(params);	
                }
                else
                {
                	$.messager.alert("系统提示","请选择要修改的信息!");
                }
            }
            function deleteit()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("系统提示","请选择要删除的数据！");
                }
                else
                {
                    $.messager.confirm("系统提示","如确认将一并删除其下所有子菜单？",function(conf){
                        if(conf)
                        {
                            var url = "${ctx}/manage/sysMenus/delete?id="+row.id;
                            $.getJSON(url, function(json){
                                if(json.success==0)
                                {
                                    $('#dg').treegrid('reload');
                                }
                                else
                                {
                                    showErrMsg(json);
                                }
                            });
                        }                                       
                    });
                }
                
            }
            function action_fun()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("系统提示","请选择要管理操作地址的功能菜单！");
                }
                else if(row.type != 3){
                	$.messager.alert("系统提示","功能类型的菜单才能添加Action！");
                }
                else
                {
                    $('#mod_id').val(row.id);
                    var url = "${baseUrl}/manage/sysMenus/actionUrl?id="+row.id;
                    var params = {
                            winId:'win_action_modules',
                            title:'设置访问URL',
                            width:300,
                            height:270,
                            showUrl:url,
                            refresh_fun:function(){
                                $('#dg').treegrid('reload');
                            }
                            
                    };
                    open_fun(params);   
                }
        
            }
            </script>
	</div>
	
    <script type="text/javascript">
    	var updateFlag=false;
    	
    	 $(document).ready(init);
	     function init() {
	         $('#dg').treegrid({             
	             onLoadSuccess: function(row,data) {
	             	if(data.success != 0)
	             	{
	             		showErrMsg(data);
	             	}
	             }
	         });
	     }    
    			
    	function showType(value,rec,index)
    	{
            if(value==1)
                return "<font color='green'>菜单组</font>";
            else if(value==2)
                return "<font color='red'>菜单项</font>";
            else
                return "<font color='yellow'>功能</font>";
    	}
	</script>
	
  </body>
</html>
